<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>ming</title>
    <meta name="keywords" content="ming管理系统">
    <meta name="description" content="ming管理系统">
    <link rel="shortcut icon" href="../static/favicon.ico" th:href="@{favicon.ico}">
    <link href="../static/plugins/bootstrap/css/bootstrap.min.css" th:href="@{/plugins/bootstrap/css/bootstrap.min.css}" rel="stylesheet">
    <link href="../static/plugins/awesome/css/font-awesome.css?v=4.4.0" th:href="@{/plugins/awesome/css/font-awesome.css?v=4.4.0}" rel="stylesheet">
    <link href="../static/plugins/animate/css/animate.css" th:href="@{/plugins/animate/css/animate.css}" rel="stylesheet">
    <link href="../static/css/style.css" th:href="@{/css/style.css}" rel="stylesheet">
    <link href="../static/css/login.css" th:href="@{/css/login.css}" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>

</head>

<body class="signin">
<div class="signinpanel">
    <div class="row">
        <div class="col-sm-12">
            <form id="signupForm">
                <h3 class="text-center">用户登录</h3>
                <p class="m-t-md text-center">欢迎登录ming后台管理系统</p>
                <input type="text" name="username" class="form-control uname"
                       th:value="${username}"/>
                <input type="password" name="password"
                       class="form-control pword m-b" th:value="${password}"/>

                <div class="row">
                    <div class="col-xs-6 pull_left">
                        <div class="form-group">
                            <input class="form-control" type="tel" name="verify" id="verify"
                                   placeholder="请输入验证码" maxlength="4" autocomplete="off">
                        </div>
                    </div>
                    <div class="col-xs-6 pull_left">
                        <a href="javascript:void(0);" rel="external nofollow" title="点击更换验证码">
                            <img style="margin-top: 12px;" id="imgVerify" src="" alt="更换验证码" height="36" width="100%" onclick="getVerify(this);">
                        </a>
                    </div>
                </div>
                <a id="login" class="btn btn-login btn-block">登录</a>
                <!--按钮模块-->
                <div class="outside-login">
                    <div class="outside-login-tit">
                        <span>代码链接</span>
                    </div>
                    <div class="outside-login-cot">
                        <a class="outside-login-btn wxoa actived oschina J-btnSwitchLoginType" target="_Blank"
                           href="https://blog.csdn.net/m1090760001">
                            <em><i class="fa fa-home"></i></em>
                            <span>CSDN主页</span>
                        </a>
                        <a class="outside-login-btn wxoa actived my J-btnSwitchLoginType" target="_Blank"
                           href="https://gitee.com/jie_ming514/ming">
                            <em><i class="fa fa-git-square"></i></em>
                            <span>码云仓库</span>
                        </a>
                        <a class="outside-login-btn wxoa actived git J-btnSwitchLoginType" target="_Blank"
                           href="https://github.com/jieming514/ming">
                            <em><i class="fa fa-github"></i></em>
                            <span>GitHub仓库</span>
                        </a>
                    </div>
                </div>

            </form>
        </div>
    </div>
    <div class="signup-footer">
        <div class="pull-left">&copy; 2020 All Rights Reserved. ming
        </div>
    </div>
</div>
<script th:inline="javascript">
    var ctx = [[${#request.getContextPath()}]] ;
</script>
<!-- 全局js -->
<script src="../static/plugins/jQuery/js/jquery.min.js?v=2.1.4" th:src="@{/plugins/jQuery/js/jquery.min.js?v=2.1.4}"></script>
<script src="../static/plugins/bootstrap/js/bootstrap.min.js?v=3.3.7" th:src="@{/plugins/bootstrap/js/bootstrap.min.js?v=3.3.7}"></script>

<!-- 自定义js -->
<script src="../static/js/content.js?v=1.0.0" th:src="@{/js/content.js?v=1.0.0}"></script>

<!-- jQuery Validation plugin javascript-->
<script src="../static/js/ajax-util.js" th:src="@{/js/ajax-util.js}"></script>
<script src="../static/plugins/validate/js/jquery.validate.min.js"
        th:src="@{/plugins/validate/js/jquery.validate.min.js}"></script>
<script src="../static/plugins/validate/js/messages_zh.min.js"
        th:src="@{/plugins/validate/js/messages_zh.min.js}"></script>
<script src="../static/plugins/layer/js/layer.min.js" th:src="@{/plugins/layer/js/layer.min.js}"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#login").on('click', function () {
            $("#signupForm").submit();
        });
        validateRule();
        //回车监听事件
        $("body").keydown(keyDownLogon);
        // getVerify($("#imgVerify"));
        $("#imgVerify").click()
    });

    $.validator.setDefaults({
        submitHandler: function () {
            login();
        }
    });

    function login() {
        $.ajax({
            type: "POST",
            url: ctx + "/login",
            data: $('#signupForm').serialize(),
            success: function (r) {
                if (r.code == 0) {
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });
                    parent.location.href = ctx + '/index';
                } else {
                    layer.msg(r.msg);
                }
            },
        });
    }

    function keyDownLogon() {
        if (event.keyCode == "13") {
            $("#login").trigger('click');
        }
    }


    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                username: {
                    required: true
                },
                password: {
                    required: true
                }
            },
            messages: {
                username: {
                    required: icon + "请输入您的用户名",
                },
                password: {
                    required: icon + "请输入您的密码",
                }
            }
        });
    }

    //获取验证码
    function getVerify(obj) {
        obj.src = ctx + "/getVerify?" + Math.random();
    }
</script>
</body>
</html>
